#pragma once


#define GMP 1

#undef DRAW_DIAGONALS //1

typedef figureVertice Vertex;
//typedef reinterpret_cast<T>() cast<T>()
//we need a stack to keep the points
typedef std::stack<figureVertice> verticeStack;


//We will use a vertQueue as a list of vertices in y-coord order


//Point list 
typedef DoublyList<Vertex>        verticeList;
typedef verticeList::iterator     vertIterator;

class Triangulation
{
protected:
  vertQueue     m_vertQueue;
  verticeStack  m_vertStack;
  diagonalList  m_diagList; //it should be sorted by y-coords TODO:
  //trianList     m_triangles;
  //figPoints     m_points;
  
  Vertex				 m_prevVert;
  bool          m_prepared;

  diagonalList  m_diagProcessedList;
  verticeList   m_doublyList;
public:
  Triangulation(void);
  Triangulation(const Face &);
  ~Triangulation(void);
  virtual void Triangulate();
  void  SetFace(const Face &);
  void  TriangleExtract(const HWND &, const POINT &);
protected:
  virtual void DifferentChain(const figureVertice &);
  virtual void IdenticalChain(const figureVertice &);
  virtual void AddDiagonal(const figureVertice &, const figureVertice &); 
  virtual bool IsIntersection(const figureEdge &);
  virtual bool IsIntersection(const figureVertice &, const figureVertice &);
  virtual bool IsAngleCheck(const figureVertice &, const figureVertice &);
  virtual const figureEdge & FindDiagonal(Vertex v1, Vertex v2);
  virtual Vertex GetHighestPoint();
  void FindAShortestDiagonalWay();
  int DiagonalCostWay(const figureEdge & diagonal);
};
